import os, re, time

if os.path.isfile("o1000k.ap"):
    a = time.clock()
    data = open("o1000k.ap").read()
    #a4 = time.clock() - a    
    links = re.findall('GET .* HTTP|EAD .* HTTP|OST .* HTTP', data)
    #a3 = time.clock() - a    
    def chik(x): return x[4:-5]
    links = map(chik, links)
    links.sort()
    
    j = 0
    num = 0
    dictionary = [[links[0],0]]
    #a2 = time.clock() - a
    for i in xrange(len(links)):
        if links[i]==dictionary[j][0]: num=num+1
        else:
            dictionary[j][1] = num
            j=j+1
            dictionary.append([links[i],0])
            num = 1
    dictionary[j][1]=num
    file = open("log.txt", "w")
    for i in xrange(len(dictionary)):
        file.write(dictionary[i][0]+" - "+str(dictionary[i][1])+"\r\n")
    a1 = time.clock() - a
    #file.write("Time of calculation: "+str(a4)+" "+str(a3)+" "+str(a2)+" "+str(a1))
    file.write("Time of calculation: "+str(a1))
    file.close()